#!/bin/bash

jlink_script="flash.jlink"

rm -f "$jlink_script"
# 生成jlink脚本
# connect           连接设备
# h                 暂停cpu
# loadfile "$1"     下载二进制
# r                 reset
# g                 开始运行
# exit              断开连接
cat << EOF > "$jlink_script"
device STM32F103ZE
si JTAG
speed 4000
jtagconf -1,-1
connect
h
loadfile "$1"
r
g
exit
EOF

JLinkExe -commanderscript "$jlink_script"

rm -f "$jlink_script"